To display an image on a computer display, pixel data must be produced which contains information regarding how each pixel of the display must act to produce the image. An application typically renders the image to be displayed to a provided pixel grid. The size of the grid is based on the size of the image to be rendered. The pixel grid corresponds to a pixel data file that stores the information needed to display the image on the computer display. The information includes a pixel data value for each pixel contained within the image. When the image is to be displayed, the pixel grid in the pixel data file is mapped onto an actual area of a display, and, along with pixel data values from other images collocated on the same area of the display, the pixel data values are used to determine how pixels on the display should function.
Typically, a pixel data value for a pixel is contained in four bytes. The first three bytes specify the red, green, and blue values for the pixel. In older graphics environments, the fourth byte is ignored. This fourth byte was included only because most processor designs can deal more effectively with memory in four-byte increments than in three-byte increments, and so, for storing pixel display information, the cost in storage was made up for by the processing efficiency.
When an application renders an image to be displayed to an existing pixel data file, the application which renders the image overwrites some or all of the data in the pixel data file. The resulting file is then used, alone or in combination, to describe the functioning of pixels on a display to display the image.
Alpha-Blending
As described above, the fourth byte of a pixel data value is not used in older graphics environments. In newer graphics environments, however, the fourth byte is used to store an alpha value (also called an alpha channel), which is used in a technique known as alpha blending.
Alpha blending is a method for simulating transparency when a display is made up of overlapping layers of images. In alpha blending, the alpha value of each pixel specifies an opacity level for that pixel. In particular, an alpha value of 0 indicates that the pixel is fully transparent, and an alpha value of 255 indicates that the pixel is fully opaque (non-transparent). An intermediate alpha value (one between 0 and 255) indicates an intermediate level of opacity. The alpha value of a pixel of an image in the foreground determines to what extent any information from any collocated pixels in background images will be displayed.
For an example of a use of alpha-blending, consider a computer display with an icon displayed on top of a background pattern. To create such a display using alpha blending, a pixel data file is used which stores information about how the icon should be drawn. Within this pixel data file for the icon, for some pixels, the stored alpha value is greater than 0. These pixels are opaque, and it is these opaque pixels that make up the image of the icon. All the other pixels in the stored grid of pixel data have an alpha value of zero. These pixels are transparent and are not part of the image of the icon. When the pixel data from the pixel data file corresponding to the icon is displayed on top of a background pattern image corresponding to the background pattern, the icon is displayed, and the background pattern image shows through in any areas where the pixel data file for the icon indicated that the pixels are transparent. Additionally, if any pixels in the icon image have a value of less than 255 (full opacity) some information from the background image pattern may be viewed through the icon image.
Generally, when alpha blending is used, pixels in a foreground image that have a non-zero alpha value are displayed either in combination with those in a background image, or, in the case of total opacity of the foreground image, in place of those in a background image. The background image shows though unobscured where any pixels in the icon image have an alpha value of zero. In this way, a graphics environment that implements alpha blending (an alpha-channel-aware environment) can use the alpha channel values to display combinations of images that overlap.
Non-Alpha-Channel-Aware Applications
Alpha blending and the use of the alpha value are not known by many older applications (non-alpha-channel-aware applications) that create pixel data files. In the usual case, a non-alpha-channel-aware application takes as input a pixel data file to be written to, and, in that pixel data file, overwrites the pixel data value for any number of pixels. In this way, a new image is written into the pixel data file. Any image information which had previously existed in the input image data file is overwritten in each pixel that has been written to by the non-alpha-channel-aware application. The output of the non-alpha-channel-aware application is the partially or totally rewritten pixel data file.
Importantly, when new pixel information is written in to the pixel data file, many non-alpha-channel-aware applications set the last byte of the pixel data value to zero for each pixel that is overwritten. This byte is the byte used as the alpha value in alpha-channel-aware-applications.
Using A Non-Alpha-Channel-Aware Application in an Alpha-Channel-Aware Environment
When a non-alpha-channel-aware application generates a pixel data file for use with an alpha-channel-aware environment, an issue arises in that the alpha value for each pixel in the image drawn by the non-alpha-channel-aware application is set to zero. Pixel data not created by the non-alpha-channel-aware application is not changed by the non-alpha-channel-aware application, so the original alpha value of such pixel data (which may be greater than zero) is retained. These pixels may appear if the pixel data file is used in an alpha-channel-aware environment. But because pixel data created by the non-alpha-channel-aware application has an alpha value of zero, every pixel for which a pixel data value was written to the pixel data file by the non-alpha-channel-aware application is transparent. These pixels will not appear when the pixel data file is used in an alpha-channel-aware environment.
Therefore, in order to use the output of non-alpha-channel-aware application in an alpha-channel-aware context, some method must be used to modify the alpha values of the pixel data. Changing the opacity of all the pixels to a non-zero value, regardless of whether they have been written to by the non-alpha-channel-aware application, would result in some opacity of all pixels in the image, even those that were not written by the non-alpha-channel-aware application and are not part of the intended image.
Recognizing such a condition, and in the prior art, a mechanism was established whereby when initializing the pixel data file to be allotted to the application, the pixel data value for every pixel is set to a sentinel value or color. Then, after the application has written the image to the pixel data file, the pixel data value for every pixel is examined. If a particular pixel data value still has the sentinel value or color, the alpha value for that pixel is set to zero. If the particular pixel data value does not contain the sentinel value, the alpha value for that pixel is set to a desired opacity.
Significantly, such mechanism has two drawbacks. First, the mechanism is computationally expensive in that every pixel must be read and compared to the sentinel value, and possibly re-written. Secondly, if the non-alpha-channel-aware application happens to write a pixel to a value that matches the sentinel value, such written pixel is erroneously rendered transparent.
Accordingly, a need exists for a method and mechanism for allowing a non-alpha-channel-aware application to render an image for an alpha-channel-aware environment. More particularly, a need exists for such a method and mechanism that is computationally inexpensive and does not cause erroneously transparent pixels.